#include "StdAfx.h"
#include <string>
#include "RegOptHelper.h"
#include "SettingHdr.h"
#include "FilterSetting.h"

FilterSetting::FilterSetting()
:m_WinProp(Reg_WinPath)
,m_DeskProp(Reg_DeskPath)
,m_LrcProp(Reg_LrcPath)
{
     // Read value from window's register
     if( !DeserializeFromReg() )
         SetDefaultVal();
}

FilterSetting::~FilterSetting()
{
     SerializeToReg();
}


bool FilterSetting::SerializeToReg()
{
     // Reg location
     const TCHAR * Path = Gbl_Path;
     // Open the reg key
     DWORD Disp = REG_OPENED_EXISTING_KEY;
     HKEY FilterKey;
     if( RegCreateKeyEx(HKEY_LOCAL_MACHINE, Path, 0, NULL, REG_OPTION_NON_VOLATILE,
         KEY_WRITE, NULL, &FilterKey, &Disp) !=ERROR_SUCCESS )
	     return false;

     // Put key to realse helper
     RegKeyReleaseHelper AutoReleaseFilterKey(FilterKey);

     // Save show mode value
     SaveRegDWORDVal(FilterKey, _T("ShowMode"), m_ShowMode, return false);

     return true;
}

bool FilterSetting::DeserializeFromReg()
{
     // Reg location
     const TCHAR * Path = Gbl_Path;
     // Open the reg key
     HKEY FilterKey;
     if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, Path, 0, KEY_READ, &FilterKey) !=ERROR_SUCCESS )
	     return false;

     // Put key to realse helper
     RegKeyReleaseHelper AutoReleaseFilterKey(FilterKey);

     // Get show mode value
     DWORD Holder = 0;
     QueryRegDWORDVal(FilterKey, _T("ShowMode"), Holder, return false);
     m_ShowMode = (ShowMode)Holder;

     return true;
}

void FilterSetting::SetDefaultVal()
{
     m_ShowMode = WinMode;
}
